<{include file="admin/admin_head.html"}>
<body>
	<{include file="admin/admin_nav.html"}>
	<h1>文章分类</h1>
	<div id="cat-list">
		<ul>
			<li class="list-head">
				<span>
					<input type="checkbox" id="check-all" />
				</span>
				<span>分类ID</span>
				<span>分类名称</span>
				<span>所属分类</span>
				<span>操作</span>
			</li>
			<{foreach from=$list item=cat}>
			<li>
				<span>
					<input type="checkbox" id="check-all" />
				</span>
				<span><{$cat.id}></span>
				<span><{$cat.name}></span>
				<span><{if $cat.p_name}><{$cat.p_name}><{else}>无<{/if}></span>
				<span>
					<a href="javascript:;" class="edit_cat" data="{cid:'<{$cat.id}>',cname:'<{$cat.name}>',pid:'<{$cat.p_id}>'}">修改</a>
					<a href="javascript:;" class="del_cat" data="<{$cat.id}>">删除</a>
				</span>
			</li>
			<{/foreach}>
		</ul>
	</div>
	<fieldset id="cat-from" name="cat-form">
	<legend>添加分类</legend>
	<form action="article.php" method="post" id="frm-edit">
		<span><label for="name">分类名称：</label><input type="text" name="name" /></span>
		<span>
			<label for="pid">所属分类：</label>
			<select name="pid">
				<option value="0">无</option>
				<{foreach from=$list item=cat}>
				<option value="<{$cat.id}>"><{$cat.name}></option>
				<{/foreach}>
			</select>
		</span>
		<span>
			<input type="submit" value="提交" />
			<input type="hidden" name="action" value="addCategory" />
			<input type="hidden" name="cid" value="0" />
		</span>
	</form>
	</fieldset>
<script type="text/javascript">
$(document).ready(function(){
	$(".edit_cat").click(function(){
		var data = eval("(" + $(this).attr("data") + ")");
		$("#frm-edit input[name=name]").val(data.cname);
		$("#frm-edit input[name=cid]").val(data.cid);
		$("#frm-edit input[name=action]").val("editCategory");
		$("#frm-edit select[name=pid]").val(data.pid);
	})

	$(".del_cat").click(function(){
		var id = $(this).attr("data");
		if( id!="" && confirm("确定要删除该分类吗？") ){
			$.ajax({
				url: 'article.php?action=delCategory&cid='+id,
				success: function(data){
					if( data==1 ){
						alert('删除成功！')
					}else{
						alert('删除失败！')
					}
					location.reload();
				}
			})
		}
	})
})
</script>
</body>
</html>